import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class TestStaggeredGridView extends StatelessWidget {
  const TestStaggeredGridView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("瀑布流GridView"),
      ),
      body: Padding(
        padding: const EdgeInsets.only(top: 12.0),
        child: MasonryGridView.count( // 替换为MasonryGridView
          crossAxisCount: 4,
          mainAxisSpacing: 4.0,
          crossAxisSpacing: 4.0,
          itemCount: _tiles.length,
          itemBuilder: (context, index) {
            return _tiles[index];
          },
        ),
      ),
    );
  }
}

const List<Widget> _tiles = [
  _Example01Tile(backgroundColor: Colors.green, iconData: Icons.widgets),
  _Example01Tile(backgroundColor: Colors.lightBlue, iconData: Icons.wifi),
  _Example01Tile(backgroundColor: Colors.amber, iconData: Icons.panorama_wide_angle),
  _Example01Tile(backgroundColor: Colors.brown, iconData: Icons.map),
  _Example01Tile(backgroundColor: Colors.deepOrange, iconData: Icons.send),
  _Example01Tile(backgroundColor: Colors.indigo, iconData: Icons.airline_seat_flat),
  _Example01Tile(backgroundColor: Colors.red, iconData: Icons.bluetooth),
  _Example01Tile(backgroundColor: Colors.pink, iconData: Icons.battery_alert),
  _Example01Tile(backgroundColor: Colors.purple, iconData: Icons.desktop_windows),
  _Example01Tile(backgroundColor: Colors.blue, iconData: Icons.radio),
];

class _Example01Tile extends StatelessWidget {
  const _Example01Tile({
    required this.backgroundColor,
    required this.iconData,
  });

  final Color backgroundColor;
  final IconData iconData;

  @override
  Widget build(BuildContext context) {
    return Card(
      color: backgroundColor,
      child: InkWell(
        onTap: () {},
        child: Center(
          child: Padding(
            padding: const EdgeInsets.all(4.0),
            child: Icon(
              iconData,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}
